import pandas as pd
import get_content

excel_file = '/Users/yyq/code/simple-util-py/test/resoucres/创新人才库20241204130739.xlsx'

df = pd.read_excel(excel_file)
length = len(df)
list_ = []
last_index = 1
for i in range(2, length):
    id = df.iloc[i, 0]
    if pd.isna(id):
        continue
    else:
        list_.append(df.iloc[last_index:i].values)
        last_index = i
info_list: list[dict] = []
for info in list_:
    length = len(info)
    # 基础信息
    base_info = {
        'id': info[0][0],
        'title': info[0][1],
        'bianhao': int(info[0][2]),
        'name': info[0][3],
        'gender': info[0][4],
        'both': info[0][5],
        'gongsi': info[0][6],
        'zhiwu': info[0][7],
        'zhicheng': info[0][8],
        'gzsj': info[0][9],
        'phone': int(info[0][10]),
        'email': info[0][11],
        'create_time': info[0][61],
        'create_people': info[0][62]
    }

    jyjl_list = []  # 教育经历
    zy_list = []  # 专业
    zyzgzs_list = []  # 职业资格证书
    gzjl_list = []  # 工作经历
    xmyj_list = []  # 项目业绩
    hjqk_list = []  # 获奖情况
    zb_or_cb_bz = []  # 主编或参编标准
    dbxgf_list = []  # 代表性工法
    zl_list = []  # 专利及软著
    lw_list = []  # 论文及著作
    qc_list = []  # QC成果
    for i in range(length):
        info_ = info[i]
        if not pd.isna(info_[12]):
            jyjl_list.append(info_[12:17])
        if not pd.isna(info_[17]):
            zy_list.append(info_[17:19])
        if not pd.isna(info_[19]):
            zyzgzs_list.append(info_[19:22])
        if not pd.isna(info_[22]):
            gzjl_list.append(info_[22:27])
        if not pd.isna(info_[27]):
            xmyj_list.append(info_[27:33])
        if not pd.isna(info_[33]):
            hjqk_list.append(info_[33:39])
        if not pd.isna(info_[39]):
            zb_or_cb_bz.append(info_[39:44])
        if not pd.isna(info_[44]):
            dbxgf_list.append(info_[44:49])
        if not pd.isna(info_[49]):
            zl_list.append(info_[49:53])
        if not pd.isna(info_[53]):
            lw_list.append(info_[53:57])
        if not pd.isna(info_[57]):
            qc_list.append(info_[57:62])

    info_list.append({
        'base_info': base_info,
        'jyjl_list': jyjl_list,
        'zy_list': zy_list,
        'zyzg_list': zyzgzs_list,
        'gzjl_list': gzjl_list,
        'xmyj_list': xmyj_list,
        'hjqk_list': hjqk_list,
        'zb_or_cb_bz': zb_or_cb_bz,
        'dbxgf_list': dbxgf_list,
        'zl_list': zl_list,
        'lw_list': lw_list,
        'qc_list': qc_list,
    })

print("*" * 70)
for i in range(len(info_list)):
    for values in info_list[i].values():
        if values:
            if type(values) == dict:
                for k, v in values.items():
                    if pd.isna(v):
                        values[k] = ''
            if type(values) == list:
                for i in range(len(values)):
                    for j in range(len(values[i])):
                        if pd.isna(values[i][j]):
                            values[i][j] = ''


def shanghangju_post():
    from request_kms import post_rich_content_knowledge_detail
    cids = []
    kids = []
    cate = 1656
    for info in info_list:
        c, k = post_rich_content_knowledge_detail(cate)
        cids.append(c)
        kids.append(k)
    print(cids)
    print(kids)


def shanghangju():
    from request_kms import (approve, put_rich_content_knowledge_detail)

    success = False
    ids = 1907
    for info in info_list:
        content = get_content.get_content1(info)
        success = put_rich_content_knowledge_detail(
            knowledge_id=ids,
            name=info['base_info']['name'],
            content=content,
            cate_id=ids)
        approve(ids)
        ids += 1


def devkms_post():
    from request_kms_test import post_rich_content_knowledge_detail
    cids = []
    kids = []
    for info in info_list:
        c, k = post_rich_content_knowledge_detail()
        cids.append(c)
        kids.append(k)
    print(cids)
    print(kids)


def devkms():
    from request_kms_test import put_rich_content_knowledge_detail
    success = False
    cate_ids = [
        74990, 74991, 74992, 74993, 74994, 74995, 74996, 74997, 74998, 74999,
        75000, 75001, 75002, 75003, 75004, 75005, 75006, 75007, 75008, 75009,
        75010, 75011, 75012, 75013
    ]
    knowledge_ids = [
        75378, 75379, 75380, 75381, 75382, 75383, 75384, 75385, 75386, 75387,
        75388, 75389, 75390, 75391, 75392, 75393, 75394, 75395, 75396, 75397,
        75398, 75399, 75400, 75401
    ]
    index = 0
    for info in info_list:
        content = get_content.get_content1(info)
        success = put_rich_content_knowledge_detail(
            knowledge_id=knowledge_ids[index],
            name=info['base_info']['name'],
            content=content,
            cate_id=cate_ids[index])
        index += 1


shanghangju()
